require 'rubygems'
require 'mongrel'

class SimpleHandler < Mongrel::HttpHandler
  class Const
    ContentType = 'Content-Type'.freeze
    TextHtml = 'text/html'.freeze
    HTML = '<html><body><h1>%s %s</h1><p>%s</p></body></html>'.freeze
  end

  def process(request, response)
    response.start(200) do |head,out|
      head[Const::ContentType] = Const::TextHtml
      out.write(Const::HTML % [
        request.params[Mongrel::Const::REQUEST_METHOD],
        request.params[Mongrel::Const::PATH_INFO],
        ENV.inspect
      ])
    end
  end
end


h = Mongrel::HttpServer.new("0.0.0.0", "4401")
h.register("/test", SimpleHandler.new)
h.register("/", Mongrel::DirHandler.new("."))
h.run.join
